<?php
/**
 * Delete Maintenance types
 * 
 */

use Common\Agency;

$id = Xview::instance()->val("id");
$action = "agencies";
if(empty($id))
{
	Xview::instance()->systemError();exit;
}

try {
	$object = new Agency($id);
	$label = $object->label();
}
catch (Fox\Object\Exception\NotExist $e)
{
	Xview::instance()->systemError();exit;
}
if(Xview::instance()->val("confirmation"))
{
	try {
		$object->delete();
		echo Fox\Message::Information(Msg(Fox::MSGCL,43,$label));
		exit;
	}
	catch (Fox\Object\Exception\Save $e)
	{
		Fox\Core\Errors::pushMessage($e);
	}
}

$reload = "Refresh(\'?mod=maintenance&act=$action\');";
$yesAction = "FoxPostForm('deleteForm','?mod=maintenance&act=$action&sac=delete&id=$id','$reload',null,null,null,'&confirmation=true')";
$popup = new Fox\Popup\ToConfirm("deleteForm",Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_DELETE_HDR,$label), Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_DELETE_MSG_CONF,$label),$yesAction,null,400);
echo $popup->Display();